//
//  MiniWindowController.m
//  ChimooTimer
//
//  Created by Ryan on Thu May 13 2004.
//  Copyright (c) 2004 Chimoosoft. All rights reserved.
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

#import "MiniWindowController.h"
#import "CMSTimeFormatter.h"

@implementation MiniWindowController

- (void)awakeFromNib {
	defaults = [[NSUserDefaults standardUserDefaults] retain];
	
	[miniWindow setLevel:NSNonactivatingPanelMask];
	[miniWindow setFloatingPanel:YES];
	[miniWindow setBecomesKeyOnlyIfNeeded:YES];
	[miniWindow setHidesOnDeactivate:NO];
}



- (void)updateDisplayWithSeconds:(double)seconds {
	[textField setDoubleValue:seconds];
}

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize {
	NSSize newSize = proposedFrameSize;
	newSize.height = [sender frame].size.height;
	
	return newSize;
}

- (BOOL)windowShouldClose:(id)sender {
	[defaults setBool:NO forKey:@"showMiniWindow"];
	return YES;
}

// Toggles the mini window on and off.
- (IBAction)toggleMiniWindow:(id)sender {
	
	if ([miniWindow isVisible]) {
		// So make it invisible
		[miniWindow orderOut:self];		
	} else {
		// It's invisible, so make it visible.	
		[miniWindow makeKeyAndOrderFront:nil];			
	}
}

- (BOOL)canBecomeKeyWindow {
	return NO;
}

- (void)dealloc {

	[defaults release];
	[super dealloc];
}

@end
